#include <iostream>
#include <cmath>
using namespace std;

int factor_digits(int num, int *digits, int limit)
{
    int digits_count = 0;

    while(num/(int)pow(10,limit-1) > 0)
    {
        digits[digits_count++] = num % (int)pow(10,limit);
        num /= 10;
    }
    
   return num/(int)pow(10,limit) ? 0 : digits_count;
}

bool prime(int n) {
    if (n == 1) return false;
    else
    {
        for(int i=2; i<=sqrt(n); i++)
		    if(n % i == 0)
			    return false;
    }
	return true;
}

int maxint(int arr[], int count)
{
    int max = arr[0];
    for(int i=1; i < count; i++)
    {
        if(arr[i] > max)
            max = arr[i];
    }
    return max;  
}


int main()
{
    int n;
    int factored_number[20];
    int primed_numbers[20];
    int factored_number_len;
    int i;
    int k = 0;
    
    cin >> n;

    if((int)n <= 999 && (int)n > 9999)
    {
        cout << 0 << endl;
    }
    
    if(prime(n))
        cout << n << endl;
    else
    {
        factored_number_len = factor_digits(n, factored_number, 1);
    
        for (i = factored_number_len - 1; i >= 0; i--) {
            if(prime(factored_number[i]))
            {
                primed_numbers[k++] = factored_number[i];
            }
            
        }
    
        factored_number_len = factor_digits(n, factored_number, 2);
    
    
        for (i = factored_number_len - 1; i >= 0; i--) {
            if(prime(factored_number[i]))
            {
                primed_numbers[k++] = factored_number[i];
            }
            
        }
        
        factored_number_len = factor_digits(n, factored_number, 3);
        
        for (i = factored_number_len - 1; i >= 0; i--) {
            if(prime(factored_number[i]))
            {
                primed_numbers[k++] = factored_number[i];
            }
            
        }
        
        cout << maxint(primed_numbers, size(primed_numbers)) << endl;
        
    }

    return 0;
}